package com.example.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

/**
 * 学生实体类
 * 仅用于Elasticsearch索引
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "student")
public class Student {
    
    @Id
    private String id;
    
    @Field(type = FieldType.Text, analyzer = "ik_smart")
    private String name;
    
    @Field(type = FieldType.Integer)
    private Integer age;
    
    @Field(type = FieldType.Long)
    private Long height;
    
    @Field(type = FieldType.Keyword, index = false)
    private String number;
    
    @Field(type = FieldType.Object)
    private Parent parent;
    
    @Field(type = FieldType.Object)
    private Parents parents;
    
    @Field(type = FieldType.Object)
    private Query query;
    
    /**
     * 父母信息（嵌套对象）
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Parent {
        @Field(type = FieldType.Text)
        @JsonProperty("father")
        private String father;
        
        @Field(type = FieldType.Text)
        @JsonProperty("mother")
        private String mother;
    }
    
    /**
     * 父母信息（带分析器）
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Parents {
        @Field(type = FieldType.Text, analyzer = "ik_smart")
        @JsonProperty("father")
        private String father;
        
        @Field(type = FieldType.Text, analyzer = "ik_smart")
        @JsonProperty("mother")
        private String mother;
    }
    
    /**
     * 查询相关信息
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Query {
        @Field(type = FieldType.Object)
        @JsonProperty("fuzzy")
        private Fuzzy fuzzy;
        
        @Data
        @NoArgsConstructor
        @AllArgsConstructor
        public static class Fuzzy {
            @Field(type = FieldType.Text)
            private String value;
            
            @Field(type = FieldType.Integer)
            private Integer fuzziness;
        }
    }
}